﻿using System;

namespace FunctionalCLR.Core.Function.Flow {

    /// <summary>
    /// try({normal operation code},{exception handling code});
    /// </summary>
    public class TryNode : FuncNode {

        public TryNode()
            : base() {
            base.Value = "try";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            try {
                Children[Children.Count - 1].Evaluate();
            } catch (FunctionalCLRException ex) {
                Children[Children.Count - 2].Evaluate();
            }
            if (Children.Count > 2) {
                Children[Children.Count - 3].Evaluate();
            }

            return null;
        }
    }
}
